package rexsee.natives;

import rexsee.core.browser.Browser;
import android.view.View;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemSelectedListener;
import android.widget.Gallery;

public class GalleryOnItemSelectedListener
		implements
		OnItemSelectedListener {

	private final Browser mBrowser;
	private final Gallery mGallery;

	public GalleryOnItemSelectedListener(Browser browser, Gallery gallery) {
		mBrowser = browser;
		mGallery = gallery;
	}

	@Override
	public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
		ViewTag tag = (ViewTag) mGallery.getTag();
		if (tag != null) {
			mBrowser.eventList.run(RexseeJavaView.EVENT_ONGALLERYCHANGED, new String[]{tag.id, String.valueOf(position)});
		}
	}
	@Override
	public void onNothingSelected(AdapterView<?> arg0) {
		ViewTag tag = (ViewTag) mGallery.getTag();
		if (tag != null) {
			mBrowser.eventList.run(RexseeJavaView.EVENT_ONGALLERYCHANGED, new String[]{tag.id, "-1"});
		}
	}

}
